package cn.edu.sgu.www.mhxysy.service.xingshi.impl;

import cn.edu.sgu.www.mhxysy.entity.xingshi.XingshiXianghun;
import cn.edu.sgu.www.mhxysy.entity.xingshi.XingshiXianghunCategory;
import cn.edu.sgu.www.mhxysy.mapper.xingshi.XingshiXianghunCategoryMapper;
import cn.edu.sgu.www.mhxysy.mapper.xingshi.XingshiXianghunMapper;
import cn.edu.sgu.www.mhxysy.service.xingshi.XingshiXianghunService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class XingshiXianghunServiceImpl implements XingshiXianghunService {

    private final XingshiXianghunCategoryMapper xingshiXianghunCategoryMapper;
    private final XingshiXianghunMapper xingshiXianghunMapper;

    @Autowired
    public XingshiXianghunServiceImpl(
            XingshiXianghunCategoryMapper xingshiXianghunCategoryMapper,
            XingshiXianghunMapper xingshiXianghunMapper) {
        this.xingshiXianghunCategoryMapper = xingshiXianghunCategoryMapper;
        this.xingshiXianghunMapper = xingshiXianghunMapper;
    }

    @Override
    public XingshiXianghunCategory selectByXingshiId(String xingshiId) {
        QueryWrapper<XingshiXianghun> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("xingshi_id", xingshiId);

        XingshiXianghun xingshiXianghun = xingshiXianghunMapper.selectOne(queryWrapper);

        if (xingshiXianghun != null) {
            Integer xianghunId = xingshiXianghun.getXianghunId();

            return xingshiXianghunCategoryMapper.selectById(xianghunId);
        }

        return null;
    }

}